import {defineStore} from 'pinia'
import axios from "axios";
import {nanoid} from "nanoid";

export const useTalkStore = defineStore('talk', {
  //state要写成一个函数 ===真正存数据的地方
  actions: {
    getATalk() {
      axios.get('https://api.uomg.com/api/rand.qinghua?format=json').then(res => {
        //这个写法是连续解构赋值加重命名
        let {data:{content:title}} = res
        console.log(res.data)
        //把字符串包装成对象
        let obj = {id: nanoid(),title }
        this.talkList.unshift(obj)
      })
    }
  },
  state() {
    return {
      talkList: [
        {id: 1, title: '标题一'},
        {id: 2, title: '标题二'},
        {id: 3, title: '标题三'}
      ]
    }
  }
})